# 导包
import pymysql

# 创建链接
conn = pymysql.connect(host="211.103.136.244",
                       port=7061,
                       user="student",
                       password="iHRM_student_2021",
                       database="test_db",
                       charset="utf8")
# 获取游标
cursor = conn.cursor()
# 执行sql
# 查询t_book表中全局数据
sql = "select * from t_book;"
cursor.execute(sql)
# 获取第一行数据
print("游标的初始位置:", cursor.rownumber)
print(cursor.fetchone())
print("获取一行后的游标的位置:", cursor.rownumber)
# 获取查询结果集的第三条第四条记录
cursor.rownumber = 2
cursor.fetchmany(2)
# 获取全部的查询结果集及总记录数
cursor.rownumber = 0
print("获取全部的查询结果集:", cursor.fetchall())
print("总记录行数:", cursor.rowcount)
cursor.close()
conn.close()
